${package}


import com.wyl.niupi.frameworkExt.controller.BaseControllerExt;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

<#-- 判断是否有isDelete这个字段 -->
<#assign hasIsDelete=false/>
<#list fieldForGeneratorList as field>
<#if (field.columnRealName=="isDelete")>
    <#assign hasIsDelete=true/>
</#if>
</#list>

/**
 * @author ${author} on ${date}
 */
@Tag(name = "${controllerName}", description = "${tableComment}相关接口")
@RestController
@RequestMapping("${requestMapping}")
public class ${controllerName} extends BaseControllerExt {

    @Autowired
    private ${javabeanName}Service ${javabeanVar}Service;

    @Operation(summary = "获取列表", parameters = {
        @Parameter(name = "where_字段名称_过滤规则", example = "where_cname_like", required = false),
        @Parameter(name = "page", example = "1", description = "如果page和row都不为空则进行分页", required = false),
        @Parameter(name = "rows", example = "15", description = "如果page和row都不为空则进行分页", required = false),
    }, description = "详细描述...")
    @GetMapping("/list")
    public ResponseVo<PageResultVo<List<${javabeanName}>>> list(HttpServletRequest request){
        QueryWrapper queryWrapper = getQueryWrapper(request);
        <#if (hasIsDelete)>
        queryWrapper.eq(${javabeanName}.IS_DELETE, Const.IS_NO);
        </#if>

        IPage<${javabeanName}> ipage = getPage(request);
        if (null != ipage) {
            ipage = ${javabeanVar}Service.selectPage(ipage, queryWrapper);
            List<Vo<${javabeanName}>> list = Vo.list(ipage.getRecords());
            return sendSuccess(list);
        } else {
            List list = ${javabeanVar}Service.list(queryWrapper);
            return sendSuccess(list);
        }
    }

    @Operation(summary = "根据id获取", parameters = {
        @Parameter(name = "lid", example = "1", description = "主键", required = true),
    })
    @GetMapping("/get")
    public ResponseVo<${javabeanName}> get(@RequestParam("lid") Integer lid) {
        ${javabeanName} bo = ${javabeanVar}Service.getById(lid);
        return sendSuccess(bo);
    }

    @Operation(summary = "添加")
    @PostMapping("/add")
    public ResponseVo add(${javabeanName} bo) {
        <#if (hasIsDelete)>
        bo.setIsDelete(Const.IS_NO);
        </#if>
        boolean b = ${javabeanVar}Service.save(bo);
        return sendSuccess(b);
    }

    @Operation(summary = "根据id删除", parameters = {
        @Parameter(name = "lid", example = "1", description = "主键", required = true),
    })
    @PostMapping("/delete")
    public ResponseVo delete(@RequestParam("lid") Integer lid) {
        <#if (hasIsDelete)>
        ${javabeanName} bo = ${javabeanVar}Service.getById(lid);
        bo.setIsDelete(Const.IS_YEW);
        boolean b = ${javabeanVar}Service.updateById(bo);
        <#else>
        boolean b = ${javabeanVar}Service.removeById(lid);
        </#if>
        return sendSuccess(b);
    }

    @Operation(summary = "根据id修改", parameters = {
        @Parameter(name = "lid", example = "1", description = "主键", required = true),
        @Parameter(name = "其他属性", description = "传什么属性就修改什么，不传的属性不修改", required = false),
    })
    @PostMapping("/update")
    public ResponseVo update(@RequestParam("lid") Integer lid, HttpServletRequest request) {
        try {
            ${javabeanName} oldBo = ${javabeanVar}Service.getById(lid);
            _BeanUtil.copyPropertiesFromRequest(oldBo, request);
            boolean b = ${javabeanVar}Service.saveOrUpdate(oldBo);
            return sendSuccess(b);
        }catch (IllegalAccessException | InvocationTargetException e) {
            return sendError(e.getMessage());
        }
    }


}

